<template>
    <div class="l-rblock l-form-viewer" style="padding:8px;">
        <el-form
            :model="formData"
            :rules="rules"
            size="mini"
            labelPosition="right"
            labelWidth="100px"
            ref="form"
            >
            <div class="l-auto-window only-tabs">
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane class="l-tabs-container" :label="$t('密码规则')" name="tab0">
                        <el-row :gutter="0">
                            <div class="l-rblock">
                                <el-col v-if="lr_formLookAuth('lr_other_passwordrule_f_SecretLevel')" :span="24" >
                                    <el-form-item 
                                        :label="$t('人员密级')" 
                                        prop="lr_other_passwordrule_f_SecretLevel"
                                        > 
                                        <l-select :disabled="!lr_formEditAuth('lr_other_passwordrule_f_SecretLevel',false || isReadOnly)"  :options="lr_other_passwordrule_f_SecretLevelOptions" v-model="formData.lr_other_passwordrule_f_SecretLevel" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('lr_other_passwordrule_f_Day')" :span="24" >
                                    <el-form-item 
                                        :label="$t('更换周期/天')" 
                                        prop="lr_other_passwordrule_f_Day"
                                        > 
                                        <el-input-number  :disabled="!lr_formEditAuth('lr_other_passwordrule_f_Day', isReadOnly)" :min="1" controlsPosition="default" v-model="formData.lr_other_passwordrule_f_Day" :placeholder="$t('请输入')" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('lr_other_passwordrule_f_Length')" :span="24" >
                                    <el-form-item 
                                        :label="$t('密码长度')" 
                                        prop="lr_other_passwordrule_f_Length"
                                        > 
                                        <el-input-number  :disabled="!lr_formEditAuth('lr_other_passwordrule_f_Length', isReadOnly)" :min="6" controlsPosition="default" v-model="formData.lr_other_passwordrule_f_Length" :placeholder="$t('请输入')" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('lr_other_passwordrule_f_Complexity')" :span="24" >
                                    <el-form-item 
                                        :label="$t('复杂度')" 
                                        prop="lr_other_passwordrule_f_Complexity"
                                        > 
                                        <l-select :disabled="!lr_formEditAuth('lr_other_passwordrule_f_Complexity',false || isReadOnly)"  :multiple="true" :options="lr_other_passwordrule_f_ComplexityOptions" v-model="formData.lr_other_passwordrule_f_Complexity" />
                                    </el-form-item>
                                </el-col>
                                <el-col v-if="lr_formLookAuth('lr_other_passwordrule_f_Description')" :span="24" >
                                    <el-form-item 
                                        :label="$t('备注')" 
                                        prop="lr_other_passwordrule_f_Description"
                                        > 
                                        <el-input type="textarea"  :disabled="!lr_formEditAuth('lr_other_passwordrule_f_Description',isReadOnly)" :rows="5" v-model="formData.lr_other_passwordrule_f_Description" :placeholder="$t('请输入')" />
                                    </el-form-item>
                                </el-col>
                            </div>
                        </el-row>
                    </el-tab-pane>

                </el-tabs>
            </div>
        </el-form>
    </div>
</template>
<script>
const api = window.$api.systemconfig.otherPasswordRule

export default {
    props: {
        isReadOnly: {
            type: Boolean,
            default: false
        }
    },
    data(){
        return {
            moduleCode: 'systemconfig_otherPasswordRule',
            activeName: 'tab0',
            formData: {
                lr_other_passwordrule_f_SecretLevel:"", // 人员密级
                lr_other_passwordrule_f_Day:"1", // 更换周期/天
                lr_other_passwordrule_f_Length:"6", // 密码长度
                lr_other_passwordrule_f_Complexity:"", // 复杂度
                lr_other_passwordrule_f_Description:"", // 备注
                lr_other_passwordrule_f_Type:2, // 类型(1角色，2密级)
            },
            rules: {
                lr_other_passwordrule_f_SecretLevel:[
                    { required: true, message: this.$t('请选择人员密级') },
                ],
                lr_other_passwordrule_f_Day:[
                    { required: true, message: this.$t('请输入更换周期/天') },
                ],
                lr_other_passwordrule_f_Length:[
                    { required: true, message: this.$t('请输入密码长度') },
                ],
                lr_other_passwordrule_f_Complexity:[
                    { required: true, message: this.$t('请选择复杂度') },
                ],

            },
            
        };
    },
    computed: {
        lr_other_passwordrule_f_SecretLevelOptions(){
            return [{"value":0,"label":this.$t("非密")},{"value":2,"label":this.$t("一般")},{"value":3,"label":this.$t("重要")},{"label":this.$t("核心"),"value":4}]
        },
        lr_other_passwordrule_f_ComplexityOptions(){
            return [{"value":"1","label":this.$t("大写字母")},{"value":"2","label":this.$t("小写字母")},{"value":"3","label":this.$t("数字")},{"label":this.$t("特殊字符"),"value":"4"}]
        },

    },
    methods: {
        
        
        // 重置表单
        resetForm() {
            this.$formClear(this.$refs.form)
            this.activeName = 'tab0'
            
        },
        // 校验表单
        async validateForm() {
            if (!await this.$formValidateWraper(this.$refs.form)) {
                return false  
            }
            
            return true
        },
        // 设置表单数据
        setForm(data) {
            this.$setFormData(this.formData,data,'lr_other_passwordrule')

        },
        // 获取表单数据
        getForm() {
            return this.$getFormData(this.formData,'lr_other_passwordrule')

        },

        async loadFormData({ keyValue/*,params,node*/ }) {//  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
            const data = await this.$awaitWraper(api.get(keyValue))
            if (data) {
                this.setForm(data)
                return true
            }
            else {
                return false
            }
        },

        async saveForm({ keyValue, isEdit/*,code,node*/ }) {// isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
            const postData = this.getForm()
            if (isEdit) {// 编辑
                return await this.$awaitWraper(api.update(keyValue, postData))
            }
            else {// 新增
                postData.f_Id = keyValue

                return await this.$awaitWraper(api.add(postData))
            }
        },
    }
}
</script>